package com.hz.springboot01.interceptor;

import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * @author ZHL
 * @date 2023/12/11 14:37
 * @description  拦截器类
 */

@Component
public class MyInterceptor implements HandlerInterceptor {
    //preHandle是请求执行前执行的
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("进入拦截器");
        return true;
    }
    //postHandler是请求结束执行的 当preHandle返回true才会执行
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception {
        System.out.println("请求结束执行 进入 拦截器");

    }
    //afterCompletion是视图渲染完成后才执行
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception {
        System.out.println("进入 视图渲染拦截器");
    }
}
